using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Indeco.G24.Services;
using Indeco.G24.Entities;
using Indeco.G24.Web;
using Indeco.G24.Web.Data;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxGridView;

namespace Indeco.G24.Website.Price
{
    public partial class Default : G24Page
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsCallback)
            {
                System.Threading.Thread.Sleep(1000); // Intentionally pauses server-side processing, to demonstrate the Loading Panel functionality.
            }
            //if(!string.IsNullOrEmpty(Request.Params["Photo"])) {
            //    BinaryImageHelper.PostImage(Response, Request.Params["Photo"]);
            //}
            if (!IsPostBack)
            {
                DataBindToBangGiaSanPham(new Guid("2f6fe56b-fd9a-4be4-b50b-d5d22433eb8c"));
                DataBind();
                //ASPxListBox1.SelectedIndex =
                //ASPxListBox1.Items.IndexOfValue(AccessDataSource2.SelectParameters["EmployeeID"].DefaultValue);
            }
            BangGiaSanPham.ExpandAll();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void callbackPanelDiaBan_Callback(object source, CallbackEventArgsBase e)
        {
            DataBindToBangGiaSanPham(new Guid(e.Parameter));
            BangGiaSanPham.ExpandAll();

            //AccessDataSource2.SelectParameters["EmployeeID"].DefaultValue = e.Parameter;
        }
        private void DataBindToBangGiaSanPham(Guid IDDiaBan)
        {
            BangGiaSanPhamDataSource bangGiaSanPhamDataSource = new BangGiaSanPhamDataSource();
            bangGiaSanPhamDataSource.EnableDeepLoad = true;
            bangGiaSanPhamDataSource.EnableRecursiveDeepLoad = true;
            bangGiaSanPhamDataSource.SelectMethod = BangGiaSanPhamSelectMethod.GetPaged;
            bangGiaSanPhamDataSource.EnableSorting = true;
            bangGiaSanPhamDataSource.DeepLoadProperties.Method = Data.DeepLoadType.IncludeChildren;
            bangGiaSanPhamDataSource.DeepLoadProperties.Recursive = true;

            BangGiaSanPhamProperty bangGiaSanPhamProperty = new BangGiaSanPhamProperty();
            bangGiaSanPhamProperty.Name = Data.Bases.BangGiaSanPhamChildEntityTypes.SanPham;
            bangGiaSanPhamDataSource.DeepLoadProperties.Types.Add(bangGiaSanPhamProperty);

            SanPhamProperty sanPhamProperty = new SanPhamProperty();
            sanPhamProperty.Name = Data.Bases.SanPhamChildEntityTypes.SanPhamDanhMuc;
            bangGiaSanPhamDataSource.DeepLoadProperties.Types.Add(sanPhamProperty);

            BangGiaSanPhamProperty bangGiaSanPhamProperty1 = new BangGiaSanPhamProperty();
            bangGiaSanPhamProperty1.Name = Data.Bases.BangGiaSanPhamChildEntityTypes.NhaCungCap;
            bangGiaSanPhamDataSource.DeepLoadProperties.Types.Add(bangGiaSanPhamProperty1);

            BangGiaSanPhamProperty bangGiaSanPhamProperty2 = new BangGiaSanPhamProperty();
            bangGiaSanPhamProperty2.Name = Data.Bases.BangGiaSanPhamChildEntityTypes.NgoaiTe;
            bangGiaSanPhamDataSource.DeepLoadProperties.Types.Add(bangGiaSanPhamProperty2);

            BangGiaSanPhamProperty bangGiaSanPhamProperty3 = new BangGiaSanPhamProperty();
            bangGiaSanPhamProperty3.Name = Data.Bases.BangGiaSanPhamChildEntityTypes.DiaBan;
            bangGiaSanPhamDataSource.DeepLoadProperties.Types.Add(bangGiaSanPhamProperty3);

            ///========            
            SqlParameter sqlParameter = new SqlParameter();
            sqlParameter.Name = "WhereClause";
            sqlParameter.UseParameterizedFilters = false;
            DiaBanFilter diaBanFilter = new DiaBanFilter();
            diaBanFilter.Column = DiaBanColumn.IDDiaBan;
            diaBanFilter.ComparisionType = Data.SqlComparisonType.Equals;
            diaBanFilter.DefaultValue = IDDiaBan.ToString();
            sqlParameter.Filters.Add(diaBanFilter);
            bangGiaSanPhamDataSource.Parameters.Add(sqlParameter);
            BangGiaSanPham.DataSource = bangGiaSanPhamDataSource;
            BangGiaSanPham.DataBind();
            BangGiaSanPham.GroupBy((GridViewDataColumn)BangGiaSanPham.Columns[0]);
            BangGiaSanPham.GroupBy((GridViewDataColumn)BangGiaSanPham.Columns[1]);
        }

       
    }
}
